package news.config;

import news.interceptor.AdminTokenInterceptor;
import news.interceptor.UserTokenInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;

@Configuration
public class WebConfig implements WebMvcConfigurer{

	public void addInterceptors(InterceptorRegistry registry) {
		InterceptorRegistration inter =  registry.addInterceptor(new AdminTokenInterceptor());
		inter.addPathPatterns("/admin/**"); //管理员需要拦截过滤地址
		inter.excludePathPatterns("/admin/login/login");//放行地址

		InterceptorRegistration userinter =  registry.addInterceptor(new UserTokenInterceptor());
		userinter.addPathPatterns("/userApi/userCtl/**"); //管理员需要拦截过滤地址
		userinter.excludePathPatterns("/userApi/userCtl/createYzm");//放行地址
		userinter.excludePathPatterns("/userApi/userCtl/save");//放行地址
		userinter.excludePathPatterns("/userApi/userCtl/userLogin");//放行地址


		//放行行前台首页,文章详细信息等地址

		inter.excludePathPatterns("/swagger*/**"); //放行swagger
		inter.excludePathPatterns("/v2/**");//放行swagger
		inter.excludePathPatterns("/webjars/**");//放行swagger
	}

	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		registry.addResourceHandler("swagger-ui.html").addResourceLocations(
				"classpath:/META-INF/resources/");
		registry.addResourceHandler("/webjars/**").addResourceLocations(
				"classpath:/META-INF/resources/webjars/");
	}
}
